<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/newQuotation.do"/>

<%@page import="java.util.ArrayList,
                  com.scalar.chiptrack.utils.ConfigManager,
                  com.scalar.chiptrack.commons.SessionKeys,
                  com.scalar.chiptrack.commons.Constants,
                  com.scalar.chiptrack.users.User,
                  com.scalar.chiptrack.users.Functionality,
				  com.scalar.chiptrack.sales.CustomerPartNumber,
                java.util.HashMap,
                com.scalar.chiptrack.sales.ContactPerson,
                com.scalar.chiptrack.sales.forms.quote.QuotationForm,
                com.scalar.chiptrack.sales.Quotation" %>
<%@ page import="com.scalar.chiptrack.sales.LineItem" %>

<%
    String chipTracContext = "/" + ConfigManager.getChipTracContext();
    int i=0;
    String selectedMethod       = null;
    String selectedAccount      = null;
    QuotationForm quotationForm = (QuotationForm)request.getAttribute("QuotationForm");
    HashMap  quotationMap       = ( HashMap ) session.getAttribute( "quotationMap" );
    Quotation quotationFromMap  = null;
%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<SCRIPT language="JavaScript">
var prevPrice = 0;
<%
    if ( quotationMap != null )
    {
        quotationFromMap = ( Quotation )( quotationMap.get( quotationForm.getCustomerId() + "" ) );
        if( quotationFromMap != null )
        {
            pageContext.setAttribute( "billingAddressContactPersons", quotationFromMap.getContactPersonsForBillingAddress() );
            pageContext.setAttribute( "shippingAddressContactPersons", quotationFromMap.getContactPersonsForShippingAddress() );
            pageContext.setAttribute( "shippingAddresses", quotationFromMap.getShippingAddresses () );
            pageContext.setAttribute( "contactPersons", quotationFromMap.getContactPersons () );
            pageContext.setAttribute( "salesPersons", quotationFromMap.getSalesPersons() );
            pageContext.setAttribute( "salesReps", quotationFromMap.getSalesReps() );
            pageContext.setAttribute( "odmList", quotationFromMap.getOdmList() );
            pageContext.setAttribute( "endCustomerList", quotationFromMap.getEndCustomerList() );
            request.setAttribute( "changedLineItems", quotationFromMap.getChangedLineItems() );
            request.setAttribute( "prvApprovedLineItems", quotationFromMap.getPrvApprovedLineItems() );
        }
        ArrayList lineItemsList = (ArrayList) request.getAttribute ( "lineItems" );
        if ( lineItemsList == null )
        { lineItemsList = (ArrayList) session.getAttribute ( "lineItems" );}
        ArrayList customerPartNumbers = new ArrayList();
        try{
           java.util.HashMap mapCustPartNos = quotationFromMap.getMfgPartsWithCustomerPartNos() ;
           for (int j = 0; j < lineItemsList.size(); j++) {
                LineItem lineItem = (LineItem) lineItemsList.get(j);
                if ( lineItem.getManufacturingPartNo() != null && lineItem.getManufacturingPartNo().trim().length() > 0)
                {
                    customerPartNumbers = (ArrayList)mapCustPartNos.get(lineItem.getManufacturingPartNo());
                }
                request.setAttribute( "customerPartNumbers"+lineItem.getLineItemNo(),  customerPartNumbers);
           }
        }
        catch(Exception ex) {
          System.out.println(ex);
          ex.printStackTrace();
        }
    }
    HashMap contactPersonsList = quotationFromMap.getCustomerContactPersonMap();
    if(contactPersonsList != null)
    {
        int listSize = contactPersonsList.size();
        java.util.Iterator contactPersonsIterator = contactPersonsList.keySet().iterator();
        ContactPerson contactPersons[] = new ContactPerson[listSize];
        %>
            var customerContactPerson = new Array(<%=listSize%>);
            var customerPhNo          = new Array(<%=listSize%>);
            var customerCellNo        = new Array(<%=listSize%>);
            var customerFax           = new Array(<%=listSize%>);
            var customerEmail         = new Array(<%=listSize%>);
            customerContactPerson[-3] = '';
            customerContactPerson[-2] = -1;
            customerContactPerson[-1] = '';
        <%
         for( int aa = 0; aa < listSize ; aa++ )
         {
            Object key = ( String )contactPersonsIterator.next();
            if( contactPersonsList.get(key)!= null )
             {
                 if(contactPersonsList.containsKey(key))
                 {
                     contactPersons[aa] = (ContactPerson)contactPersonsList.get(key);
                    %>
                        customerContactPerson[<%=aa%>] = '<%=contactPersons[aa].getContactPerson().replaceAll("'","\\\\" + "'")%>';
                        customerPhNo[<%=aa%>]          = '<%=contactPersons[aa].getPhoneNumber().replaceAll("'","\\\\" + "'")%>';
                        customerCellNo[<%=aa%>]        = '<%=contactPersons[aa].getCellNumber().replaceAll("'","\\\\" + "'")%>';
                        customerFax[<%=aa%>]           = '<%=contactPersons[aa].getFaxNumber().replaceAll("'","\\\\" + "'")%>';
                        customerEmail[<%=aa%>]         = '<%=contactPersons[aa].getEmail()%>';
                    <%
                }
            }
        }
    }
%>

<%
    HashMap billAddressList = quotationFromMap.getBillingAddressMap();
    if(billAddressList != null)
    {
        int billListSize = billAddressList.size();
        java.util.Iterator billContactPersonsIterator = billAddressList.keySet().iterator();
        String billAddresses[] = new String[billListSize];
        %>
            var billContactPerson = new Array(<%=billListSize%>);
            var billAddress       = new Array(<%=billListSize%>);
            billContactPerson[-3] = '';
            billContactPerson[-2] = -1;
            billContactPerson[-1] = '';
        <%
        for( int bb = 0; bb < billListSize ; bb++)
        {
           Object key = (String)billContactPersonsIterator.next();
           if( billAddressList.get(key)!= null )
           {
                if(billAddressList.containsKey(key))
                {
                    billAddresses[bb] = (String)billAddressList.get(key);
                    %>
                        billContactPerson[<%=bb%>]  = '<%=key.toString().replaceAll("'","\\\\" + "'")%>';
                        billAddress[<%=bb%>]        = '<%=(billAddresses[bb].toString()).replace('\n','~').replaceAll("'","\\\\" + "'")%>';

                    <%
                }
            }
        }
    }
%>
<%
    HashMap shipAddressList = quotationFromMap.getShippingAddressMap();
    if(shipAddressList != null)
    {
        int shipListSize = shipAddressList.size();
        java.util.Iterator shipContactPersonsIterator = shipAddressList.keySet().iterator();
        String shipAddresses[] = new String[shipListSize];
        %>
            var shipContactPerson = new Array(<%=shipListSize%>);
            var shipAddress       = new Array(<%=shipListSize%>);
            shipContactPerson[-3] = '';
            shipContactPerson[-2] = -1;
            shipContactPerson[-1] = '';
        <%
        for( int bb = 0; bb < shipListSize ; bb++)
        {
           Object key = (String)shipContactPersonsIterator.next();
           if( shipAddressList.get(key)!= null )
           {
                if(shipAddressList.containsKey(key))
                {
                    shipAddresses[bb] = (String)shipAddressList.get(key);
                    %>
                        shipContactPerson[<%=bb%>] = '<%=key.toString().replaceAll("'","\\\\" + "'")%>';
                        shipAddress[<%=bb%>]          = '<%=(shipAddresses[bb].toString()).replace('\n','~').replaceAll("'","\\\\" + "'")%>';
                    <%
                }
            }
        } //for
    }
%>

<%
    ArrayList shipArr = quotationFromMap.getShippingMethods();
    int size1 = 0;
    if( shipArr !=  null )
    {
        size1 = shipArr.size();
    }
%>
    var shppingLables = new Array(<%=size1%>);
    var shppingValues = new Array(<%=size1%>);
<%
    if( shipArr != null )
    {
%>
        shppingLables[-2] = '';
        shppingLables[-1] = '';
<%
        for(int s = 0 ; s < shipArr.size() ; s++)
        {
%>
            shppingLables[<%=s%>] = '<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getLabel().replaceAll("'","\\\\" + "'")%>';
            shppingValues[<%=s%>] = '<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getValue().replaceAll("'","\\\\" + "'")%>';
<%
        }
%>
        shppingLables[<%=size1%>] = -2 ;
<%
   }
%>


    if (document.layers)
    {
        window.setResizable(false);
    }
    var count = <%= (String) session.getAttribute("maxLineItemNo") %>
    var index = 0;
    var errors  = "";
	var errors1 = "";
    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate( passedValue )
    {
        dateElement.value=passedValue;
        window.focus();
    }

    function check()
    {
       var pa1=document.getElementById("newshippingMethod");
       var pa3=document.getElementById("newshippingAccount");
       <% QuotationForm quotationForm1 = (QuotationForm)request.getAttribute("QuotationForm"); %>
        document.QuotationForm.shippingAddressId.value=<%=quotationForm1.getShippingAddressId()%>;
         <%
             String addShipMethod = request.getParameter("shipAccount1");
             if(addShipMethod==null || (!addShipMethod.equals("-2")))
             {
				 %>
				  document.QuotationForm.newshippingMethod.style.visibility = "hidden";
				  pa1.innerHTML = "";
				  document.QuotationForm.newshippingAccount.style.visibility = "hidden";
				  pa3.innerHTML = "";
				 <%
             }
             if((addShipMethod!=null) && (!addShipMethod.trim().equals("")))
             {
				 %>
				 document.QuotationForm.shippingMethod.value = '<%=addShipMethod%>'
				 document.QuotationForm.shipAccount1.value = '<%=addShipMethod%>';
				 <%
             }
         %>
         if ( document.QuotationForm.shippingMethod.value == "" )
         {
            document.QuotationForm.shippingMethod.value = "-1";
         }
         var salesTaxType = document.QuotationForm.salesTaxType.value;
         <%

             String state1 = request.getParameter ( "newSalesState" );
             String value1 = request.getParameter ( "newSalesTax" );
             if( state1 != null && value1 != null )
             {
         %>
                 if ( salesTaxType == "-1" )
                 {
                     addNewSalesTaxType( document.QuotationForm.salesTaxType );
                     document.QuotationForm.newSalesState.value = '<%=state1%>';
                     document.QuotationForm.newSalesTax.value = '<%=value1%>';
                 }
         <%  }  %>
         var shippingLabel = document.getElementById("newShippingTerms");
		if( document.QuotationForm.shippingTerms.value == -2 )
		{
			document.QuotationForm.newShippingTerms.style.visibility = "visible";
			shippingLabel.innerHTML = "New Pay Terms : ";
		}
		else
		{
			document.QuotationForm.newShippingTerms.style.visibility = "hidden";
			shippingLabel.innerHTML = "";
		}
        var deliveryTermsLabel = document.getElementById("newDeliveryTerms");
		if( document.QuotationForm.deliveryTerms.value == -2 )
		{
			document.QuotationForm.newDeliveryTerms.style.visibility = "visible";
			deliveryTermsLabel.innerHTML = "New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> : ";
		}
		else
		{
			document.QuotationForm.newDeliveryTerms.style.visibility = "hidden";
			deliveryTermsLabel.innerHTML = "";
		}
        var pa = document.getElementById("shippingInstructions");
        if ( document.QuotationForm.shippingInstructionsId.value == "-2" )
        {
            pa.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />"
            document.QuotationForm.shippingInstructions.readOnly = false;
        }
        else
        {
            pa.innerHTML = "<bean:message key="label.sales.shippingInstructions" />"
            document.QuotationForm.shippingInstructions.readOnly = true;
        }
        if(document.QuotationForm.contactPerson.value == document.QuotationForm.customerName.value )
        {
            document.QuotationForm.cellNumber.disabled = true;
        }
        else  if( document.QuotationForm.contactPerson.value == '' )
        {
             document.QuotationForm.phoneNumber.disabled = true;
             document.QuotationForm.cellNumber.disabled = true;
             document.QuotationForm.faxNumber.disabled = true;
             document.QuotationForm.email.disabled = true;
        }

        if( document.QuotationForm.contactPerson.value == '' )
        {
            document.QuotationForm.contactPerson.value = '';
            document.QuotationForm.phoneNumber.value = '';
            document.QuotationForm.cellNumber.value = '';
            document.QuotationForm.faxNumber.value = '';
            document.QuotationForm.email.value = '';

            document.QuotationForm.phoneNumber.disabled = true;
            document.QuotationForm.cellNumber.disabled = true;
            document.QuotationForm.faxNumber.disabled = true;
            document.QuotationForm.email.disabled = true;
        }
        showHideNewEndUserField();
        var form = document.QuotationForm;
        var endCustomerCtrl = form.odmId;
        var newEndCustomerNameCtrl = form.newEndCustomerName;
        var endCustomerLabelSpan = document.getElementById ( "endCustomerLabelSpan" );
        var endCustomerTxfieldSpan = document.getElementById ( "endCustomerTxfieldSpan" );
        if ( endCustomerCtrl.value == "-2" )
        {
            endCustomerLabelSpan.style.display = 'block'
            endCustomerTxfieldSpan.style.display = 'block'
        }
        else
        {
            newEndCustomerNameCtrl.value = "";
            endCustomerLabelSpan.style.display = 'none'
            endCustomerTxfieldSpan.style.display = 'none'
        }
        showHideNewCustPartNo(-1);
    }




   function addTextArea()
   {
        index = document.QuotationForm.requestDate.length;
        if ( index == null )
        {
            index = 1;
        }

        var htmltext = '<div><table border="0" width="95%"><tr><td width="7%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<input type="text" name="lineItemNo" value="'+count+'" size=6 class="txfield" disabled="true"></td>';

        htmltext = htmltext + '<input type="hidden" name="jsLineItemNo" value="'+count+'">';

        htmltext = htmltext + '<td width="7%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<input type="text" name="poLineItemNo" value="'+count+'" size=6 class="txfield" disabled="true">';
        htmltext = htmltext + '</td>';
        htmltext = htmltext + '<input type="hidden" name="poLineItemNo" value="'+count+'">';
        htmltext = htmltext + '<input type="hidden" name="lineItemId" value="-1">';


        htmltext = htmltext + '<td width="15%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<select name="manufacturingPartNo" class="txfield" ><option value="" ></option>';

        <%
            java.util.ArrayList optionlist = null;
            java.util.ArrayList mfgList = null;
            org.apache.struts.util.LabelValueBean option = null;
            CustomerPartNumber customerPartNo = new  CustomerPartNumber();
            StringBuffer strBuffer = null;
            StringBuffer strBuffer1 = null;
            int mfgListsize =0;
            try
            {
              mfgList = quotationFromMap.getMfgParts();
              if( mfgList == null)  mfgList =  new java.util.ArrayList();
              mfgListsize = mfgList.size();
              strBuffer1 = new StringBuffer();
                 for( int j = 0; j < mfgListsize; j++)
                 {
                     customerPartNo = (CustomerPartNumber)mfgList.get(j);
                     strBuffer1.append("htmltext = htmltext + '");
                     strBuffer1.append("<option value=\"").append(customerPartNo.getManufacturingPartNo()).append("\">");
                     strBuffer1.append(customerPartNo.getManufacturingPartNo()).append("</option>';\n");
                 }
              out.println(strBuffer1);
            }
            catch(Exception ex)
            {

            }
        %>
        htmltext = htmltext + '</select></td>';
		htmltext = htmltext + '<td width="10%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<select name="customerPartNo"  class="txfield" onchange="showHideNewCustPartNo(' + (count-1)+ ')"><option value="">Select Customer Part No</option><option value="-2">--Add New CustomerPart No--</option></select><input type="text" name="newCustomerPartNo" maxlength="50" size="20" value="" style="display:none;" class="txfield">';
        htmltext = htmltext + '<td width="10%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<textarea name="lineItemDescription" class="txfield" onkeydown="javascript:setTextAreaMaxLength(this,200)" onkeyup="javascript:setTextAreaMaxLength(this,200)"onchange="javascript:setTextAreaMaxLength(this,200)"></textarea></td>';
        htmltext = htmltext + '<td width="1%" bgcolor="#DEE1E2"> &nbsp;&nbsp;&nbsp;';
        htmltext = htmltext + '<input type=checkbox name="isTaxable'+count+'">&nbsp;&nbsp;&nbsp;</td>';
        htmltext = htmltext + '<td width="18%" bgcolor="#DEE1E2" nowrap>';
        htmltext = htmltext + '<input type="text" name="requestDate" size=15 class="txfield">';
        htmltext = htmltext + '<a href="javascript:openCalendar(document.QuotationForm.requestDate['+index+'])"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></img></a></td>';
        htmltext = htmltext + '<td width="10%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<td width="5%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<input type="text" name="quantity" size=8 class="valuetxfield" value="0" onchange="javascript:isValidInteger(this);"></td>';
        htmltext = htmltext + '<input type="hidden" name="oldQty" value="0">';

        htmltext = htmltext + '<td width="15%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<input type="text" name="unitPriceAsDouble" size=13 class="valuetxfield" value="0.0" onkeypress="javascript:restrictCharacters(this,7,3)" maxlength="9" onkeyup="javascript:restrictAmt(this,7,3)"></td>';
        htmltext = htmltext + '<td width="15%" bgcolor="#DEE1E2">';
        htmltext = htmltext + '<input type="text" name="amount" size=25 class="valuetxfield" value="$0.00" disabled="true"></td></tr></table></div>';

        var pa=document.getElementById("font1");
        pa.insertAdjacentHTML('BeforeEnd',htmltext);
        count++;

    }
    function AddShippingTerms ()
	{
		var shippinglabel = document.getElementById("newShippingTerms");
		if(document.QuotationForm.shippingTerms.value == -2 )
		{
			 document.QuotationForm.newShippingTerms.style.visibility = "visible";
			 document.QuotationForm.newShippingTerms.value = '';
			 shippinglabel.innerHTML = "New Pay Terms : ";
		}
		else
		{
			 document.QuotationForm.newShippingTerms.style.visibility = "hidden";
			 shippinglabel.innerHTML = "";
		}
	}
    function AddDeliveryTerms ()
	{
		var deliveryTermsLabel = document.getElementById("newDeliveryTerms");
		if(document.QuotationForm.deliveryTerms.value == -2 )
		{
			 document.QuotationForm.newDeliveryTerms.style.visibility = "visible";
			 document.QuotationForm.newDeliveryTerms.value = '';
			 deliveryTermsLabel.innerHTML = "New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> : ";
             document.QuotationForm.newDeliveryTerms.focus();
		}
		else
		{
			 document.QuotationForm.newDeliveryTerms.style.visibility = "hidden";
			 deliveryTermsLabel.innerHTML = "";
		}
	}
    function AddNewShippingAddress(addElement)
    {
        //Restricting the user from entering more than one new shipping address
        var pa = document.getElementById("errors");
        pa.innerHTML = "";

        for(var i=0;i< document.QuotationForm.shippingAddressId.length; i++) {
            if(document.QuotationForm.shippingAddressId[i].value == -1){
                pa.innerHTML = "Can not add more than one new Shipping Address'";
                return;
            }
        }

        shipElement = addElement.name;
        if(document.QuotationForm.endUser.value == '')
        {
            if( document.QuotationForm.isEndCustomerShipAddress.checked && Number( document.QuotationForm.odmId.value ) > 0 )
            {
                customerId = document.QuotationForm.odmId.value;
            }
            else
            {
                customerId = document.QuotationForm.customerId.value;
            }
            newWindow = window.open('addAddress.do?action=AddShippingAddress&customerId='+customerId,'shippingAddressPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
            newWindow.focus();
        }
        else
        {
            newWindow = window.open('addEndUserAddress.do?action=AddEndUserShippingAddress&endUserId='+document.QuotationForm.endUserId.value,'shippingAddressPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
  	        newWindow.focus();
        }

  	    newWindow.focus();
    }
    function showHideNewEndUserField()
    {
        var form = document.QuotationForm;
        var endUserCtrl = form.endCustomerId;
        var newEndUserNameCtrl = form.newEndUserName;
        var endUserLabelSpan = document.getElementById ( "endUserLabelSpan" );
        var endUserTxfieldSpan = document.getElementById ( "endUserTxfieldSpan" );
        if ( endUserCtrl.value == "-2" )
        {
            endUserLabelSpan.style.display = 'block'
            endUserTxfieldSpan.style.display = 'block'
        }
        else
        {
            newEndUserNameCtrl.value = "";
            endUserLabelSpan.style.display = 'none'
            endUserTxfieldSpan.style.display = 'none'
        }
    }

    function addShippingAddressContactPerson(shipAddressWithoutContactPerson,strShippingAddress,contactPerson)
    {
        document.QuotationForm.shippingAddress.value=strShippingAddress;
        document.QuotationForm.shippingAddressId.value=-1;
        document.QuotationForm.shippingContactPerson.length=0;
        document.QuotationForm.shippingContactPerson.length=2;
        document.QuotationForm.shippingContactPerson.options[0].text="--- Select ---";
        document.QuotationForm.shippingContactPerson.options[0].value="";
        document.QuotationForm.shippingContactPerson.options[1].text=contactPerson;
        document.QuotationForm.shippingContactPerson.options[1].value=contactPerson;
        document.QuotationForm.shippingContactPerson.value=contactPerson;

        shipContactPerson.length = 2;
        shipAddress.length = 2;

        shipContactPerson[0] = '';
        shipAddress[0]       = shipAddressWithoutContactPerson;

        shipContactPerson[1] = contactPerson;
        shipAddress[1]       = strShippingAddress;

    }
function assignShippingAddress(elementName)
{

        var  mfgValue = eval(document.QuotationForm["manufacturingPartNo"]);
        if(mfgValue.name == 'manufacturingPartNo')
        {

            document.QuotationForm.manufacturingPartNo.disabled = false;
        }
        else
        {
            for(var i=0; i< mfgValue.length; i++)
            {
                mfgValue[i].disabled=false;
            }
        }
        var x = eval(document.QuotationForm["unitPriceAsDouble"]);
        if(x.name == 'unitPriceAsDouble')
        {
            document.QuotationForm.unitPriceAsDouble.disabled = false;
			document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
            for(var i=0; i< x.length; i++)
            {
                x[i].disabled=false;
				document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.quantity.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.quantity[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.requestDate.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.requestDate[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemDescription.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemDescription[i].disabled = false;
            }
        }
       for( var txble=1; txble < count; txble++ )
       {
	        var txval = "isTaxable"+txble;
            tax = eval( document.QuotationForm[txval] )

            if(document.QuotationForm[txval] != null)
            {
	            tax.disabled = false
            }
       }

	enableCustPartNos();
    document.QuotationForm.expiryDate.disabled=false;
	document.QuotationForm.shippingAddress.disabled = false;
	document.QuotationForm.billingAddress.disabled = false;
	document.QuotationForm.action.value = "loadShippingAddress";
	document.QuotationForm.submit();
}
function assignShippingInstructions(elementName)
{
    var shippingInstructions = document.getElementById("shippingInstructions");
    if ( elementName.value == "-1" )
    {
        shippingInstructions.innerHTML = "<bean:message key="label.sales.shippingInstructions" />"
        document.QuotationForm.shippingInstructions.value = "";
        document.QuotationForm.shippingInstructions.readOnly = true;
    }
    else if ( elementName.value == "-2")
    {
        shippingInstructions.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />"
        document.QuotationForm.shippingInstructions.value = "";
        document.QuotationForm.shippingInstructions.readOnly = false;
        document.QuotationForm.shippingInstructions.focus();
    }
    else if ( Number( elementName.value ) > 0 )
    {
        var  mfgValue = eval(document.QuotationForm["manufacturingPartNo"]);
        if(mfgValue.name == 'manufacturingPartNo')
        {

            document.QuotationForm.manufacturingPartNo.disabled = false;
        }
        else
        {
            for(var i=0; i< mfgValue.length; i++)
            {
                mfgValue[i].disabled=false;
            }
        }
        var x = eval(document.QuotationForm["unitPriceAsDouble"]);
        if(x.name == 'unitPriceAsDouble')
        {
            document.QuotationForm.unitPriceAsDouble.disabled = false;
			document.QuotationForm.lineItemNo.disabled = false;

        }
        else
        {
            for(var i=0; i< x.length; i++)
            {
                x[i].disabled=false;
				document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.quantity.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.quantity[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.requestDate.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.requestDate[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemDescription.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemDescription[i].disabled = false;
            }
        }

       for( var txble=1; txble < count; txble++ )
       {
	        var txval = "isTaxable"+txble;
            tax = eval( document.QuotationForm[txval] )

            if(document.QuotationForm[txval] != null)
            {
	            tax.disabled = false
            }
       }

        enableCustPartNos();//function
        document.QuotationForm.expiryDate.disabled=false;
        document.QuotationForm.shippingAddress.disabled = false;
        document.QuotationForm.billingAddress.disabled = false;
        document.QuotationForm.action.value = "loadShippingInstructions";
        document.QuotationForm.submit();
    }
}
function setReadOnlyForFreightInsructions ( elementName )
{
    if ( elementName.value == "-1" )
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.QuotationForm.freightInstructions.readOnly = true;
        document.QuotationForm.freightInstructions.value = "";
    }
    if ( elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.QuotationForm.freightInstructions.readOnly = false;
    }
    else if ( Number( elementName.value ) > 0 )
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.QuotationForm.freightInstructions.readOnly = true;
    }
}
function assignFreightInstructions(elementName)
{
    if ( elementName.value == "-1" )
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.QuotationForm.freightInstructions.readOnly = true;
        document.QuotationForm.freightInstructions.value = "";
    }
    else if ( elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.QuotationForm.freightInstructions.readOnly = false;
        document.QuotationForm.freightInstructions.value = "";
        document.QuotationForm.freightInstructions.focus();
    }
    else if ( Number( elementName.value ) > 0 )
    {
        var  mfgValue = eval(document.QuotationForm["manufacturingPartNo"]);
        if(mfgValue.name == 'manufacturingPartNo')
        {

            document.QuotationForm.manufacturingPartNo.disabled = false;
        }
        else
        {
            for(var i=0; i< mfgValue.length; i++)
            {
                mfgValue[i].disabled=false;
            }
        }
        var x = eval(document.QuotationForm["unitPriceAsDouble"]);
        if( x.name == 'unitPriceAsDouble' )
        {
            document.QuotationForm.unitPriceAsDouble.disabled = false;
			document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
            for(var i=0; i< x.length; i++)
            {
                x[i].disabled=false;
				document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.quantity.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.quantity[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.requestDate.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.requestDate[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemDescription.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemDescription[i].disabled = false;
            }
        }

       for( var txble=1; txble < count; txble++ )
       {
	        var txval = "isTaxable"+txble;
            tax = eval( document.QuotationForm[txval] )

            if(document.QuotationForm[txval] != null)
            {
	            tax.disabled = false
            }
       }

        enableCustPartNos();//function
        document.QuotationForm.expiryDate.disabled=false;
        document.QuotationForm.shippingAddress.disabled = false;
        document.QuotationForm.billingAddress.disabled = false;
        document.QuotationForm.action.value = "loadFreightInstructions";
        document.QuotationForm.submit();
    }
}
    function getCustomerShippingAddress()
    {
        var isEndCustomerShipAddress      = document.QuotationForm["isEndCustomerShipAddress"];

        isEndCustomerShipAddress.checked = false;

        enableFormFields();
        document.QuotationForm.action.value = "loadEndCustomerDefualtShippingAddress";
        document.QuotationForm.submit();
    }
    function getEndCustomerShippingAddress(elementName)
    {
        var endCustomerId      = document.QuotationForm["odmId"];
        var pa                 = document.getElementById("errors1");
        if ( elementName.checked )
        {
            if ( endCustomerId.value == -1 )
            {
                pa.innerHTML = "<li>Please select <bean:message key="label.sales.shipToCustomer"/></li>"
                elementName.checked = false;
                return;
            }
        }
        enableFormFields();
        document.QuotationForm.action.value = "loadEndCustomerDefualtShippingAddress";
        document.QuotationForm.submit();
    }
    function enableFormFields()
    {
        var  mfgValue = eval(document.QuotationForm["manufacturingPartNo"]);
        if(mfgValue.name == 'manufacturingPartNo')
        {
            document.QuotationForm.manufacturingPartNo.disabled = false;
        }
        else
        {
            for(var i=0; i< mfgValue.length; i++)
            {
                mfgValue[i].disabled=false;
            }
        }
        var x = eval(document.QuotationForm["unitPriceAsDouble"]);
        if( x.name == 'unitPriceAsDouble' )
        {
            document.QuotationForm.unitPriceAsDouble.disabled = false;
			document.QuotationForm.lineItemNo.disabled = false;

        }
        else
        {
            for( var i=0; i< x.length; i++ )
            {
                x[i].disabled=false;
				document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemNo.disabled = false;
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemNo[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.quantity.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.quantity[i].disabled = false;
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.requestDate.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.requestDate[i].disabled = false;
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
            document.QuotationForm.lineItemDescription.disabled = false;
        }
        else
        {
           for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
                document.QuotationForm.lineItemDescription[i].disabled = false;
            }
        }

       for( var txble=1; txble < count; txble++ )
       {
	        var txval = "isTaxable"+txble;
            tax = eval( document.QuotationForm[txval] )

            if(document.QuotationForm[txval] != null)
            {
                tax.disabled = false
            }
        }

        enableCustPartNos();//function
        document.QuotationForm.expiryDate.disabled=false;
        document.QuotationForm.shippingAddress.disabled = false;
        document.QuotationForm.billingAddress.disabled = false;
    }

    //Function for adding a new option to the shippingAddressId select list
    function addShippingAddressIdOption(optionContent,optionValue)
    {
        document.QuotationForm.shippingAddressId.add(new Option(optionContent,optionValue));
    }

   function addShippingMethod(methodname)
   {
        var pa11=document.getElementById("shippingAccount");
        var pa1=document.getElementById("newshippingMethod");
        var pa3=document.getElementById("newshippingAccount");

		document.QuotationForm.shipAccount1.value = document.QuotationForm.shippingMethod.value;

          if (methodname.value == -2)
          {
    			 <%--document.QuotationForm.newshippingMethod.style.visibility = "visible";
				 pa1.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingMethod"/>:&nbsp;<font color=red>*</font>";

				 document.QuotationForm.newshippingAccount.style.visibility = "visible";
      	         pa3.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingAccount"/>:&nbsp;<font color=red>*</font>";--%>
                var form = document.QuotationForm;
                document.QuotationForm.shipAccount1.value = -1;
                form.shippingMethod.value = -1;
                form.shippingMethodName.value = " ";
                form.shippingAccount.value = " ";
                var LeftPos=(screen.width)?(screen.width-500)/2:100;
                var TopPos=(screen.height)?(screen.height-450)/2:100;
                newWindow = window.open ('<%=chipTracContext%>/shippingMethodPopupAction.do?action=load&fromScreen=quote&customerId='+form.customerId.value+"&endCustomerId="+form.odmId.value,"editShippingMethod",'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
                newWindow.focus();
          }
		  else
		  {
				if (methodname.value == -1)
				{
                    document.QuotationForm.shippingMethodName.value = " ";
				    document.QuotationForm.shippingAccount.value = " ";
				}
				document.QuotationForm.newshippingMethod.style.visibility = "hidden";
				pa1.innerHTML = "";
				document.QuotationForm.newshippingAccount.style.visibility = "hidden";
				pa3.innerHTML = "";
				assignShippingAccount(methodname);
		}
    }

    function taxFocus()
    {
         document.QuotationForm.newSalesTax.focus();
    }

    var flag = true;
    function addNewSalesTaxType(statename)
    {
          var p1=document.getElementById("font-1");
       	  var p2=document.getElementById("font-2");
	      var p3=document.getElementById("font-3");
       	  var p4=document.getElementById("font-4");

          p1.innerHTML = "";
          p2.innerHTML = "";
          p3.innerHTML = "";
          p4.innerHTML = "";

          if(statename.value == -1)
          {
          	     var htmltext1 = '<font class="NArialL">New State :</font>&nbsp;'
       		     var htmltext2 = '<input type="text" name="newSalesState" size="18" maxlength="25" class="txfield" onblur ="javascript:taxFocus();" >'
       		     var htmltext3 = '<font class="NArialL">New Tax :</font>&nbsp;'
       		     var htmltext4 = '<input type="text" name="newSalesTax" size="18" maxlength="6" class="txfield" onkeypress="javascript:restrictCharacters(this,3,2)" onkeyup="javascript:restrictAmt(this,3,2)">'

       		     p1.insertAdjacentHTML('BeforeEnd',htmltext1);
       		     p2.insertAdjacentHTML('BeforeEnd',htmltext2);

       		     p3.insertAdjacentHTML('BeforeEnd',htmltext3);
       		     p4.insertAdjacentHTML('BeforeEnd',htmltext4);
          }

     }
    function assignShippingAccount(elementName)
    {
        var len = elementName.length;

        for(var i=0; i< len; i++){
             if(elementName.options[i].selected){
                document.QuotationForm.shippingMethodName.value = elementName.options[i].innerText;

             }
        }

        if(document.QuotationForm.shippingMethod.value != -1)
        {
            document.QuotationForm.shippingAccount.value = elementName.value;
        }
        else
        if(document.QuotationForm.shippingMethod.value == -1)
        {
            document.QuotationForm.shippingAccount.value = '';
            document.QuotationForm.shippingMethodName.value = '';
        }
    }
    function isValidInteger(temp)
    {
        errors = "";
        if(!isInteger(temp.value)) {
            errors = "Please enter a valid integer";
        }
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;

        return;

    }


    function dateValidation()
    {
		var dateValue = "";
	    var temp = document.QuotationForm["requestDate"];

         if ( temp.length == null )
         {
           if( chkDate(temp.value,"Requested Dock Date","Y") == false)
			{
				errors = errMsg;
				temp.select();
				temp.focus();
			}
			else
			{
				return false;
			}
        }
        else
        {
            var partNo = document.QuotationForm["manufacturingPartNo"];
            var i;
            for( i=0; i< temp.length; i++)
            {
                if(partNo[i].value != '')
                {
                    if( chkDate(temp[i].value,"Requested Dock Date ","Y") == false)
                    {
                        errors = errMsg;
                        temp[i].select();
                        temp[i].focus();
                        break;
                    }

                }
            }
        }

        if(errors != '')
            return false;
        else
            return true;
    }

    function validateRequestDate(temp)
    {
        errors = "";
        validateDate(temp.value);
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;

    	return;
    }

function selectEndUser ()
{
    document.QuotationForm.shippingAddress.disabled = false;
	document.QuotationForm.billingAddress.disabled = false;
	document.QuotationForm.phoneNumber.disabled = false;
	document.QuotationForm.faxNumber.disabled = false;
	document.QuotationForm.email.disabled = false;

    if ( document.QuotationForm.quotation.value == 'Quotation')
            document.QuotationForm.quotation.value = 0

    var x = eval(document.QuotationForm["manufacturingPartNo"]);
    if(x.name == 'manufacturingPartNo')
    {
        document.QuotationForm.manufacturingPartNo.disabled = false;
    }
    else
    {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
        }
    }

    var x = eval(document.QuotationForm["unitPriceAsDouble"]);
    if(x.name == 'unitPriceAsDouble')
    {
        document.QuotationForm.unitPriceAsDouble.disabled = false;
        document.QuotationForm.lineItemNo.disabled = false;

    }
    else
    {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemNo.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }

    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.quantity.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.quantity[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.requestDate.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.requestDate[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemDescription.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemDescription[i].disabled = false;
        }
    }

    for( var txble=1; txble < count; txble++ )
    {
        var txval = "isTaxable"+txble;
        tax = eval( document.QuotationForm[txval] )

        if(document.QuotationForm[txval] != null)
        {
            tax.disabled = false
        }
    }
    enableCustPartNos();//function
    document.QuotationForm.expiryDate.disabled=false;
    document.QuotationForm.action.value= 'loadEndUserDetails';
    document.QuotationForm.submit();
}

function selectODM ()
{
    document.QuotationForm.shippingAddress.disabled = false;
	document.QuotationForm.billingAddress.disabled = false;
	document.QuotationForm.phoneNumber.disabled = false;
	document.QuotationForm.faxNumber.disabled = false;
	document.QuotationForm.email.disabled = false;

    if ( document.QuotationForm.quotation.value == 'Quotation')
            document.QuotationForm.quotation.value = 0

    var x = eval(document.QuotationForm["manufacturingPartNo"]);
    if(x.name == 'manufacturingPartNo') {
        document.QuotationForm.manufacturingPartNo.disabled = false;
    } else {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
        }
    }

    var x = eval(document.QuotationForm["unitPriceAsDouble"]);
    if(x.name == 'unitPriceAsDouble') {
        document.QuotationForm.unitPriceAsDouble.disabled = false;
        document.QuotationForm.lineItemNo.disabled = false;

    } else {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemNo.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }

    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.quantity.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.quantity[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.requestDate.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.requestDate[i].disabled = false;
        }
    }


    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemDescription.disabled = false;
    }
    else
    {
       for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemDescription[i].disabled = false;
        }
    }
    for( var txble=1; txble < count; txble++ )
   {
        var txval = "isTaxable"+txble;
        tax = eval( document.QuotationForm[txval] )

        if(document.QuotationForm[txval] != null)
        {
            tax.disabled = false
        }
   }


    enableCustPartNos();//function
    document.QuotationForm.expiryDate.disabled=false;
    document.QuotationForm.action.value= 'loadODMDetails';
    document.QuotationForm.submit();
}

    function selectContactPerson (element,idValue, indexValue)
    {
        var yy = document.QuotationForm.contactPerson.selectedIndex;
        if( element =='CustomerContactPerson' )
        {
            for( ss = 0; ss < customerContactPerson.length; ss++ )
            {
                if( document.QuotationForm.contactPerson.value == customerContactPerson[ss] )
                {
                     document.QuotationForm.contactPerson.value = customerContactPerson[ss];
                     document.QuotationForm.phoneNumber.value = customerPhNo[ss];
                     document.QuotationForm.cellNumber.value = customerCellNo[ss];
                     document.QuotationForm.faxNumber.value = customerFax[ss];
                     document.QuotationForm.email.value = customerEmail[ss];

                     document.QuotationForm.phoneNumber.disabled = false;
                     document.QuotationForm.cellNumber.disabled = false;
                     document.QuotationForm.faxNumber.disabled = false;
                     document.QuotationForm.email.disabled = false;
                     if( document.QuotationForm.customerName.value == customerContactPerson[ss] )
                     {
                        document.QuotationForm.cellNumber.disabled = true;
                     }
                }
                else  if( document.QuotationForm.contactPerson.value == '' )
                {
                     document.QuotationForm.contactPerson.value = '';
                     document.QuotationForm.phoneNumber.value = '';
                     document.QuotationForm.cellNumber.value = '';
                     document.QuotationForm.faxNumber.value = '';
                     document.QuotationForm.email.value = '';

                     document.QuotationForm.phoneNumber.disabled = true;
                     document.QuotationForm.cellNumber.disabled = true;
                     document.QuotationForm.faxNumber.disabled = true;
                     document.QuotationForm.email.disabled = true;
                }
            }
        }
        var ww = document.QuotationForm.billingContactPerson.selectedIndex;
    	if( element =='BillingContactPerson' )
    	{
    		 for( pp = 0; pp < billContactPerson.length; pp++ )
    		 {
    			if( document.QuotationForm.billingContactPerson.value == billContactPerson[pp] )
    			{
    				 document.QuotationForm.billingContactPerson.value = billContactPerson[pp];

    				 document.QuotationForm.billingAddress.value = billAddress[pp].replace(/~/g,'\n') ;
    			}
    		 }

    	}

    	if( element =='ShippingContactPerson' )
    	{

    		 for( ff = 0; ff < shipContactPerson.length; ff++ )
    		 {
    			if( document.QuotationForm.shippingContactPerson.value == shipContactPerson[ff] )
    			{

    				 document.QuotationForm.shippingContactPerson.value = shipContactPerson[ff];

    				 document.QuotationForm.shippingAddress.value = shipAddress[ff].replace(/~/g,'\n');
    			}
    		 }
    	}

    }
    function submitPage(action)
    {
        if ( validateForm() )
        {
            enableFields();
            if(action == 'UPDATE')
                document.QuotationForm.action.value = "UpdateSalesOrder";
            else if(action == 'SUBMIT')
                document.QuotationForm.action.value = "SubmitSalesOrder";
            else if(action == 'POST')
                document.QuotationForm.action.value = "PostQuotation"


                document.QuotationForm.submit();
        }
    }

function enableCustPartNos()
{
	var custPNo = eval('document.QuotationForm.customerPartNo');
	if (custPNo.length ==  null )
	{
		custPNo.disabled = false;
	}
	else
	{
		for (var xx = 0; xx < custPNo.length; xx++ )
		{
			custPNo[xx].disabled = false;
		}
	}
}

function enableLabelNumbers()
{
	var labelNo = eval('document.QuotationForm.labelNumber');
	if (labelNo.length ==  null )
	{
		labelNo.disabled = false;
	}
	else
	{
		for (var xx = 0; xx < labelNo.length; xx++ )
		{
			labelNo[xx].disabled = false;
		}
	}
}

function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

function selectCustomerSalesPersonRelation()
{
    var customerId = document.QuotationForm.customerId.value ;
    var customerName = document.QuotationForm.customerName.value;
    var odmId = document.QuotationForm.odmId.value ;
    var LeftPos=(screen.width)?(screen.width-500)/2:100;
    var TopPos=(screen.height)?(screen.height-450)/2:100;
    newWindow = window.open ('<%=chipTracContext%>/customerSalesPersonRelationship.do?action=searchSalesPersons&customerId='+customerId+'&odmId='+odmId,'customerSalespersons','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
    if(!newWindow.opener) {newWindow.opener = window}
    newWindow.focus();
}

function addOptionToSelect(aName, aValue)
{
    var salesPersonObj = document.QuotationForm.salesPerson;

    addOption(salesPersonObj, aName + "", aValue, salesPersonObj.options.length);
    for( var i=0 ; i < salesPersonObj.options.length ; i++ )
    {
        if(salesPersonObj.options[i].value == document.QuotationForm.salesPersonName.value)
        {
            salesPersonObj.options[i].selected = true;
        }
    }
}

function addOption(aSelect, aName, aValue, anIndex)
{
   var aOption = new Option(aName, aValue)
   aSelect.options[anIndex] = aOption;
}

function deleteAllOptions()
{

    var salesPersonObj = document.QuotationForm.salesPerson;
    var optionValue1 = document.QuotationForm.salesPerson.value;

    if( typeof salesPersonObj !='undefined' )
    {
        for( var j = salesPersonObj.options.length ; j >= 0 ; j-- )
        {
             salesPersonObj.options[j] = null;
        }
    }
}
function validateForm()
{
        errors  = "";
		errors1 = "";
        document.getElementById("errors1").innerHTML = "";
        if(!dateValidation())
        {
            errors = errors;
        }

        var qty = document.QuotationForm["quantity"];
        var price = document.QuotationForm["unitPriceAsDouble"];
        var partNo = document.QuotationForm["manufacturingPartNo"];
        var salesorderno = document.QuotationForm["quotationNo"];
        var contactPerson = document.QuotationForm["contactPerson"];
        var salesPerson = document.QuotationForm["salesPerson"];
        var endUser = document.QuotationForm["endUser"];
        var regionalRep = document.QuotationForm["regionalRep"];
        var shippingAccount = document.QuotationForm["shippingAccount"];
        var shippingTerms = document.QuotationForm["shippingTerms"];
        var deliveryTerms = document.QuotationForm["deliveryTerms"];
        var phoneNumber = document.QuotationForm["phoneNumber"];
        var email = document.QuotationForm["email"];
        var faxNumber = document.QuotationForm["faxNumber"];
        var comments = document.QuotationForm["comments"];
        var shippingInstructions = document.QuotationForm["shippingInstructions"];
        var freightInstructions = document.QuotationForm["freightInstructions"];
        var frieght = document.QuotationForm["frieghtAsDouble"];
        var misc = document.QuotationForm["miscAsDouble"];
        var prevQty = document.QuotationForm["previousQuantity"];

        document.QuotationForm.frieghtAsDouble.value = stripCharsInBag(document.QuotationForm["frieghtAsDouble"].value,"$, ");
        document.QuotationForm.miscAsDouble.value = stripCharsInBag(document.QuotationForm["miscAsDouble"].value,"$, ");

        var tempVal = false;
        var enabled = false;
		var val ;
		var tempIsTransfer ;
        var tempIsClose;
        if(document.QuotationForm["quantity"].length == null)
        {
              var value = document.QuotationForm.jsLineItemNo.value;
              tempIsTransfer = eval("document.QuotationForm.isTransfer" + value);
              tempIsClose = eval("document.QuotationForm.isClose" + value);
              if( (tempIsTransfer.checked == false  && !(tempIsTransfer.disabled)) && (tempIsClose.checked == false  && !(tempIsClose.disabled)))
              {
                errors = '<li>'+'Please select atleast one Line Item to Transfer or Close';
              }
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
		        val = (document.QuotationForm.lineItemNo[i].value);
                tempIsTransfer = eval("document.QuotationForm.isTransfer"+val);
                tempIsClose = eval("document.QuotationForm.isClose" + val);
		        if(tempIsTransfer.checked == true && !(tempIsTransfer.disabled)|| tempIsClose.checked == true && !(tempIsClose.disabled) )
                {
                    tempVal = true;
                    break;
                }
                if( !tempIsClose.disabled )
                {
                    enabled = true;
                }
            }
            if(tempVal == false && enabled == true)
            {
                errors = '<li>'+'Please select atleast one Line Item to transfer or Close';
            }
        }

        if(document.QuotationForm["quantity"].length == null)
        {
              var value = document.QuotationForm.jsLineItemNo.value;
              tempIsTransfer = eval("document.QuotationForm.isTransfer" + value);
              tempIsClose = eval("document.QuotationForm.isClose" + value);
              if( (tempIsTransfer.checked == true && !(tempIsTransfer.disabled)) && (tempIsClose.checked == true && !(tempIsClose.disabled)))
              {
                errors = '<li>'+'Both Close and Transfer cannot be selected for a line item.';
                tempIsClose.select();
              }
        }
        else
        {
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
            {
		        val = (document.QuotationForm.lineItemNo[i].value);
                tempIsTransfer = eval("document.QuotationForm.isTransfer"+val);
                tempIsClose = eval("document.QuotationForm.isClose" + val);

                if( (tempIsTransfer.checked == true && !(tempIsTransfer.disabled)) && (tempIsClose.checked == true && !(tempIsClose.disabled)))
                {
                   errors = '<li>'+'Both Close and Transfer cannot be selected for a line item.';
                   break;
                }
            }
        }
        if(document.QuotationForm["quantity"].length == null)
        {
            if(qty.value != '')
            {
                if(!isInteger(qty.value))
                {
                    errors = errors +'<br>' + "<li>  Please enter a valid quantity ";
                    qty.select();
                }
                else if(qty.disabled==false && qty.value == 0)
                {
				    errors = errors + '<br>' +"<li>  Please enter a valid quantity ";
				    qty.select();
			    }
                else if((qty.value).length > 6)
                {
					errors = errors +'<br>' + "<li>  Please enter a valid quantity (should not allow more than 6 digits)";
					qty.select();
		        }
                else if(eval(qty.value) > eval(prevQty.value))
                {
                    errors = errors +  '<br>' + "<li> Transfer Quantity Cannot be greater than the Requested Quantity "+prevQty.value;
                    qty.select();
                }
                if(partNo.value =='')
                {
                    errors = "<li>  Please enter the Ppart number ";
                }
            }
            else
            {
                errors = errors +'<br>' + "<li>  Please enter the quantity";
            }
         }
         else
         {
            for(var i=0; i< qty.length; i++)
            {
                if(partNo[i].value != '')
                {
                    if( i > 0 && partNo[i-1].value == '' )
                    {
                        errors = "<li>  Please select the Part number for line item &nbsp;" + i;
                        break;
                    }

                    if (qty[i].value != '')
                    {
			            if(!isInteger(qty[i].value))
                        {
				            errors = errors +'<br>' + "<li>  Please enter a valid quantity ";
				            qty[i].select();
							break;
			            }
                        else if(qty[i].disabled==false && qty[i].value == 0)
                        {
				            errors = errors + '<br>' +"<li>  Please enter a valid quantity ";
				            qty[i].select();
							break;
			            }

                        else  if((qty[i].value).length > 6)
                        {
				            errors = errors + '<br>' +"<li>  Please enter a valid quantity (should not allow more than 6 digits)";
				            qty[i].select();
							break;
         		        }
                        else if(eval(qty[i].value) > eval(prevQty[i].value))
                        {
                            errors = errors +  '<br>' + "<li> Transfer Quantity Cannot be greater than the Requested Quantity "+prevQty[i].value;
                            qty[i].select();
                            break;
                        }
                    }
                    else
                    {
			            errors = errors +'<br>' + "<li>  Please enter the quantity";
                        qty[i].select();
						break;
                    }
		        }

                if(partNo[0].value =='')
                {
                    errors = "<li>  Please select the Part number ";
                }
             }
         }

          if(document.QuotationForm["unitPriceAsDouble"].length == null)
          {
            if(price.value != '')
            {
                var j = 0;
                for(var k = 0; k < (price.value).length;k++)
	            {
		            var c = (price.value).charAt(k);
		            if( c == '.' )
		            {
			            j++;
                        if(j > 1 )
                        {
                            errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				        price.select();
							break;
                        }
                    }
               }
			   if(check_char_position4(price.value) || (is_Sp_Characters_frieght(price.value) == false)  )
			   {
					 errors = errors +'<br>' + "<li>  Please enter a valid price";
					 price.select();
			   }
	        }
            else
            {
	            errors = errors +'<br>' + "<li>  Please enter the price";
	        }
	      }
          else
          {
	        for(var i=0; i< price.length; i++)
	        {
	            if(partNo[i].value != '')
                {
	                if (price[i].value != '')
                    {
                        var j = 0;
                        for(var k = 0; k < (price[i].value).length;k++)
	                    {
		                    var c = (price[i].value).charAt(k);
		                    if( c == '.' )
		                    {
			                    j++;
                                if(j > 1 )
                                {
                                    errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				                price[i].select();
							        break;
                                }
		                    }
	                    }

						if(check_char_position4(price[i].value) || (is_Sp_Characters_frieght(price[i].value) == false) )
                        {
	 				        errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				        price[i].select();
							break;
	 			        }
	                }
                    else
                    {
	 			        errors = errors +'<br>' + "<li>  Please enter the price";
	                    price[i].select();
						break;
	                }
	 		    }

	            if(partNo[0].value =='')
                {
                    errors = "<li>  Please select the Part number ";
	            }
	        }
	      }

        if( !(is_Sp_Characters_frieght(frieght.value)) || (check_char_position4(frieght.value)) )
        {
            errors = errors + '<br>' + "<li>  Freight should be a number ";
        }

        if( !(is_Sp_Characters_frieght(misc.value)) || (check_char_position4(misc.value)) )
	    {
            errors = errors + '<br>' + "<li>  Miscellaneous field should be a number ";
	    }

        if( document.QuotationForm.salesTaxType.value == -1)
	    {
	        var newState = document.QuotationForm.newSalesState.value.trim();
	        var newTax = document.QuotationForm.newSalesTax.value.trim();

            if( newState.length == 0 || newState == '')
            {
                errors = errors + '<br>' + "<li>  Please enter New State ";
            }
            if( newTax.length == 0 || newTax == '')
            {
                errors = errors + '<br>' + "<li>  Please enter New Tax ";
            }
            if( (newState.length == 0 || newState == '') &&  (newTax.length == 0 || newTax == ''))
            {
                 errors = ''
                 errors = errors + '<br>' + "<li> Please enter values for New State and New Tax";
            }
            if(  newState.length != 0 && newState != '')
            {
                if( !(is_Sp_Characters_State(newState)) || (check_char_position5(newState)) )
                {
                    errors = errors + '<br>' + "<li>  Please enter a valid state ";
                }
            }
            if( newTax.length != 0 && newTax != '')
            {
			    var hh = 0;
                if( !(is_Sp_Characters_frieght(newTax)) || (check_char_position4(newTax)) )
                {
                    errors = errors + '<br>' + "<li> New sales tax should be a number";
                }
                else if(newTax == 0)
                {
                    errors = '';
                    errors = errors +'<br>' + "<li>  New Tax cannot be less than or equal to zero";
                }

                for(var d = 0; d < newTax.length;d++)
                {
                    var c = (newTax).charAt(d);
                    if( c == '.' )
                    {
                        hh++;
                        if(hh > 1)
                        {
                            errors = '';
                            errors = errors +'<br>' + "<li> New Tax should be valid number and first digit can not be space or zero ";
                            break;
                        }
                    }
                }
            }
	    }

        var statename1 = document.QuotationForm["salesTaxType"];
    	var status = false;

        for( var txble=1; txble < count; txble++ )
        {
	        var txval = "isTaxable"+txble;
            if(document.QuotationForm[txval] != null)
            {
	            if( document.QuotationForm[txval].checked == true )
                {
                    status = true;
	                if( (statename1.value == 0) && (status == true) )
	                {
                        errors = errors+ '<br>' +"<li>  Please either select Tax from Sales Tax State or uncheck Taxable field";
                        break;
	                }
                }
            }
        }

        if( (statename1.value != 0) && (status == false))
        {
            errors = errors+ '<br>' +"<li>  Please either check atleast one Taxable field or Select NonTaxable option";
        }

        var pa=document.getElementById("errors");
        pa.innerHTML = errors;

        if(  (!(is_Sp_Characters(salesorderno.value))) || (check_char_position(salesorderno.value))  )
        {
            errors = errors + '<br>' + "<li>  SalesOrderNo should be a numerical and not start with  special characters";
        }
		if( (text_area(comments.value)) == true)
		{
			errors = errors + '<br>' + "<li>  Comments should not more than 300 Characters ...";
		}

		if( (text_area(shippingInstructions.value)) == true)
		{
			errors = errors + '<br>' + "<li>  ShippingInstructions should not exceed 300 characters";
		}

		if( (text_area(freightInstructions.value)) == true)
		{
			errors = errors + '<br>' + "<li>  FreightInstructions should not exceed 300 characters";
		}

		if( salesPerson.value < 0 )
		{
			document.QuotationForm["salesPerson"].value = "";
		}

		var shipTerms = document.QuotationForm.shippingTerms.value;
		var newshipTerms = document.QuotationForm.newShippingTerms.value;
		var deliveryTerms = document.QuotationForm.deliveryTerms.value;
		var newDeliveryTerms = document.QuotationForm.newDeliveryTerms.value;
		if( shipTerms == -2 )
		{
			if( newshipTerms == '' || newshipTerms.trim().length == 0 )
			{
				errors = '<br>'+'<li> Enter New Pay Terms ';
			}
			else if( newshipTerms.indexOf('\'') >=0 || newshipTerms.indexOf('"') >= 0 )
			{
				errors = '<br>'+'<li> Enter Valid Pay Terms ';
				document.QuotationForm.newShippingTerms.select();
				document.QuotationForm.newShippingTerms.focus();
			}
		}
		if( deliveryTerms == -2 )
		{
			if ( newDeliveryTerms == '' || newDeliveryTerms.trim().length == 0 )
			{
				errors = errors+'<br>'+'<li> Enter New <bean:message key="label.sales.salesOrder.DeliveryTerms" />'
			}
			else if( newDeliveryTerms.indexOf('\'') >= 0 || newDeliveryTerms.indexOf('"') >= 0)
			{
				errors = errors+'<br>'+'<li> Enter Valid <bean:message key="label.sales.salesOrder.DeliveryTerms" />';
				document.QuotationForm.newDeliveryTerms.select();
				document.QuotationForm.newDeliveryTerms.focus();
			}
		}
        <%
                if ( ConfigManager.isEndUserMandatory() )
                {
            %>
                    if ( document.QuotationForm.endCustomerId.value == '-1' || document.QuotationForm.endCustomerId.value == '' )
                    {
                        errors1 = errors1+ '<li> Please select <bean:message key="label.sales.endUser"/>';
                        document.QuotationForm.endCustomerId.focus();
                    }
                    else if ( document.QuotationForm.endCustomerId.value == '-2' && document.QuotationForm.newEndUserName.value.trim() == '' )
                    {
                        errors1 = errors1+ '<li> Please enter new <bean:message key="label.sales.endUser"/>';
                        document.QuotationForm.newEndUserName.focus();
                    }
            <%
                }
            %>
            <%
                if ( ConfigManager.isEndCustomerMandatory() )
                {
            %>
                    if ( document.QuotationForm.odmId.value == '-1' || document.QuotationForm.odmId.value == '' )
                    {
                        errors1 = errors1+ '<li> Please select <bean:message key="label.sales.endCustomer"/>';
                        document.QuotationForm.odmId.focus();
                    }
                    else if ( document.QuotationForm.odmId.value == '-2' && document.QuotationForm.newEndCustomerName.value.trim() == '' )
                    {
                        errors1 = errors1+ '<li> Please enter new <bean:message key="label.sales.endCustomer"/>';
                        document.QuotationForm.newEndCustomerName.focus();
                    }
            <%
                }
            %>

        var errors1 = "";
		if( email.value != '' )
		{
			if(!isValidEMailId (email))
			{
				errors1=errors1 + '<br>'+'<li> Please enter a valid email address';
				email.select();
				email.focus();
				location="#e1";
			}
		}

		var salesOrderNo = document.QuotationForm.quotationNo.value ;
		if( salesOrderNo == '')
		{
			document.QuotationForm.quotationNo.focus();
			errors1 = errors1 + '<br>' + "<li>  Please enter Sales Order No";
			location="#e1";
		}
		else if( salesOrderNo != '')
		{
			if( chkSalesOrderNoBegin(salesOrderNo) )
			 {
				document.QuotationForm.quotationNo.focus();
				errors1 = errors1 + '<br>' + "<li>  Sales Order No should not start with special characters ";
				location="#e1";
			 }
			 else
			 if( ! chkSalesOrderNo(salesOrderNo) )
			 {
				 document.QuotationForm.quotationNo.focus();
				 errors1 = errors1 + '<br>' + "<li>  Please enter Valid Sales Order No ";
				 location="#e1";
			 }
		}

		if( document.QuotationForm["shippingAddress"].value == '' )
		{
			errors1=errors1+ '<br>'+'<li> Please enter shipping Address';
		}
		tempVal = false;
		if(document.QuotationForm["quantity"].length == null)
		{
			  var value = document.QuotationForm.jsLineItemNo.value;
			  tempIsTransfer = eval("document.QuotationForm.isTransfer" + value);

			  if( tempIsTransfer.checked == true  &&  !(tempIsTransfer.disabled) )
			  {
				 tempVal = true;
			  }
		}
		else
		{
		   for(var i=0; i< QuotationForm["quantity"].length; i++)
			{
				val = (document.QuotationForm.lineItemNo[i].value);
				tempIsTransfer = eval("document.QuotationForm.isTransfer"+val);

				if( tempIsTransfer.checked == true && !(tempIsTransfer.disabled) )
				{
					tempVal = true;
					break;
				}
			}
		}
		if( tempVal == true && document.QuotationForm.customerPO.value == '')
		{
			document.QuotationForm.customerPO.focus();
			errors1 = errors1 + '<br>' + "<li>  Please enter Customer PO No";
			location="#e1";
		}

		var shipmethod = document.QuotationForm.shippingMethod.value;
		var shipaccount = document.QuotationForm.shippingAccount.value;
		if(document.QuotationForm.shippingMethod.value == -2)
		{
			var newshipmethod = document.QuotationForm.newshippingMethod.value;
			var newshipaccount = document.QuotationForm.newshippingAccount.value;
			if( trim(newshipmethod) =='')
			{
				errors1 = errors1+ "<li>  Enter <bean:message key="label.sales.salesOrder.NewShippingMethod" />";
				document.QuotationForm.newshippingMethod.focus();
			}
			if(trim(newshipaccount) == '')
			{
				errors1 = errors1+ "<li>  Enter <bean:message key="label.sales.salesOrder.NewShippingAccount" />";
				document.QuotationForm.newshippingAccount.focus();
			}
			if(newshipmethod.indexOf('\'')>=0 || newshipmethod.indexOf('"')>=0 || newshipmethod.indexOf('#')>=0)
			{
				errors1 = errors1 + '<li> Enter Valid <bean:message key="label.sales.salesOrder.NewShippingMethod" /> ( \' " # are not allowed ) ';
				document.QuotationForm.newshippingMethod.select();
				document.QuotationForm.newshippingMethod.focus();
			}
			if(newshipaccount.indexOf('\'')>=0 || newshipaccount.indexOf('"')>=0 || newshipaccount.indexOf('#')>=0)
			{
				errors1 = errors1 + '<li> Enter Valid <bean:message key="label.sales.salesOrder.NewShippingAccount" /> ( \' " # are not allowed ) ';
				document.QuotationForm.newshippingAccount.select();
				document.QuotationForm.newshippingAccount.focus();
			}
			var tempShippingMethod =  newshipmethod.trim()+'   #   '+newshipaccount.trim();
			for(var i = 0; i < shppingLables.length - 1; i++)
			{
				if(  shppingLables[i].toUpperCase() == tempShippingMethod.toUpperCase() )
				{
					errors1 = errors1 + '<li>' + newshipmethod + ' <bean:message key="label.sales.salesOrder.ShippingMethod" /> already Exists, Please enter another <bean:message key="label.sales.salesOrder.ShippingMethod" />';
					document.QuotationForm.newshippingMethod.select();
					document.QuotationForm.newshippingMethod.focus();
				}
			}
		}
		if( errors1 != '' )
        {
            var pa=document.getElementById("errors1");
            pa.innerHTML = errors1;
			return false;
        }
		if( errors != '' )
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = errors;
			return false;
        }
        var description = document.QuotationForm["lineItemDescription"];
        var length = document.QuotationForm["lineItemDescription"].length
        if(length == null)
        {
            if(description.value.length > 200)
            {
				pa.innerHTML = "<li>Description Should be Maximum of 200 Characters. ";
				description.focus();
				description.select();
				return false;
            }
        }
        else
        {
            for(var i=0;i< length;i++)
            {
				if(description[i].value.length > 200)
                {
					pa.innerHTML = "<li>Description Should be Maximum of 200 Characters. ";
                    description[i].focus();
                    description[i].select();
                    return false;
				}
            }
        }
    return true;
}
function enableFields()
{
    document.QuotationForm.shippingAddress.disabled = false;
    document.QuotationForm.billingAddress.disabled = false;
    document.QuotationForm.phoneNumber.disabled = false;
    document.QuotationForm.faxNumber.disabled = false;
    document.QuotationForm.email.disabled = false;
    document.QuotationForm.expiryDate.disabled=false;
    document.QuotationForm.shippingAccount.disabled=false;

    if ( document.QuotationForm.quotation.value == 'Quotation')
        document.QuotationForm.quotation.value = 0

    var x = eval(document.QuotationForm["manufacturingPartNo"]);
    if( x.name == 'manufacturingPartNo')
    {
        document.QuotationForm.manufacturingPartNo.disabled = false;
    }
    else
    {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
        }
    }

    for( var txble=1; txble < count; txble++ )
    {
        var txval = "isTaxable"+txble;
        tax = eval( document.QuotationForm[txval] )

        if(document.QuotationForm[txval] != null)
        {
            tax.disabled = false
        }
    }

    x = eval(document.QuotationForm["unitPriceAsDouble"]);
    if(x.name == 'unitPriceAsDouble')
    {
        document.QuotationForm.unitPriceAsDouble.disabled = false;
        document.QuotationForm.lineItemNo.disabled = false;
    }
    else
    {
        for(var i=0; i< x.length; i++)
        {
            x[i].disabled=false;
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemNo.disabled = false;
    }
    else
    {
        for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemNo[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.quantity.disabled = false;
    }
    else
    {
        for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.quantity[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.requestDate.disabled = false;
    }
    else
    {
        for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.requestDate[i].disabled = false;
        }
    }
    if(document.QuotationForm["quantity"].length == null)
    {
        document.QuotationForm.lineItemDescription.disabled = false;
    }
    else
    {
        for(var i=0; i< QuotationForm["quantity"].length; i++)
        {
            document.QuotationForm.lineItemDescription[i].disabled = false;
        }
    }
    enableCustPartNos();
}
function splitLineItems()
{
    var form =  document.QuotationForm;
    if ( validateForm() )
    {
        enableFields();
        form.action.value = "splitLineItems";
        form.submit();
    }
}
function resetForm()
{
    document.QuotationForm.reset();
    showHideNewCustPartNo(-1);
}
function showHideNewCustPartNo ( selectedIdx )
{
    var form = document.QuotationForm;
    if ( count > 2 )
    {
        if ( selectedIdx < 0 ) //All
        {
            for( var k = 0; k < form.customerPartNo.length; k++)
            {
                if ( form.customerPartNo[k].value == "-2" )
                {
                    form.newCustomerPartNo[k].style.display = "block";
                    form.newCustomerPartNo[k].focus();
                }
                else
                {
                    form.newCustomerPartNo[k].style.display = "none";
                }
            }
        }
        else
        {
            if ( form.customerPartNo[selectedIdx].value == "-2" )
            {
                form.newCustomerPartNo[selectedIdx].style.display = "block";
                form.newCustomerPartNo[selectedIdx].focus();
            }
            else
            {
                form.newCustomerPartNo[selectedIdx].style.display = "none";
            }
        }
    }
    else
    {
        if ( form.customerPartNo.value == "-2" )
        {
            form.newCustomerPartNo.style.display = "block";
            form.newCustomerPartNo.focus();
        }
        else
        {
            form.newCustomerPartNo.style.display = "none";
        }
    }
}
function deleteAllListOptions( listCtrl )
{
    if( typeof listCtrl !='undefined' )
    {
        for( var j = listCtrl.options.length ; j >= 0 ; j-- )
        {
             listCtrl.options[j] = null;
        }
    }
}
function addOptionToList(listCtrl, aName, aValue)
{
   addOption(listCtrl, aName, aValue, listCtrl.options.length)
}

</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0"  onload='check();'>

<% String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + ""; %>

<logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/header.jsp" %>
</logic:equal>
<logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
    <%@ include file="/jsp/includes/extHeader.jsp" %>
</logic:notEqual>



<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
		<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
			<!-- Side Navigation start -->
			<%
				String heading = "";
				if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0")))
				{
					heading = "Sample Order";
				}
				else if((request.getParameter("quotation") != null) && (request.getParameter("quotation").equals("0")))
				{
					heading = "Quote";
				}
				else
				{
					heading = "Sales Order";
				}
			%>

			<logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
				<%@ include file="/jsp/sales/sales_order_menu.jsp" %>
			</logic:equal>
			<logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
				<%@ include file="/jsp/sales/ext_sales_order_menu.jsp" %>
			</logic:notEqual>
		</TD>
		<TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8 ></TD>
		<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2 ></TD>
		<TD valign="top" width="100%">
			<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
			<BR>
			<html:html>
				<table width="75%"><tr><td ><center><span class="NArialW">Transfer Quote Entry</span></center></td></tr></table>
					<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>
                    <table border="0" width="95%" align=right>
                    <%
                        User user1 = (User) session.getAttribute (SessionKeys.USER_KEY);
                        if( !user1.isActionAllowed (Functionality.SALES_NEW_QUOTATION, User.USER_ACTION_MODIFY ) ) {
                    %>
						<tr>
							<td colspan=7 align='left'>
								<font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></font>
							</td>
						</tr>
                    <% } %>
						<html:form name="QuotationForm" action="/transferQuotation" method="post" type="com.scalar.chiptrack.sales.forms.QuotationForm">
						<input type="hidden" name="quotation" value="<%=heading%>">
						<input type="hidden" name="quotationId" value="<%=quotationForm.getQuotationId()%>" >
						<tr><td><a name="#e1"></a></td></tr>
						<tr><td colspan=6 class="NArialL"><chiptrack:errors styleClass="NArialL"  /></td></tr>
						<tr><td  colspan="6" align="left" class='NArialL'><FONT id="errors1" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
                        <tr>
						   <td width="11%">&nbsp;</td>
						   <td width="17%">&nbsp;</td>
						   <td width="13%" class="NArialL">Quotation No</td>
						   <td width="20%" class="bodytext"><b><bean:write name="QuotationForm" property="salesOrderQuoteNo" /></b></td>
						   <td width="25%">&nbsp;</td>
						   <td width="13%">&nbsp;</td>
						</tr>
                        <tr>
						   <td width="11%"><font class="NArialL">SalesOrder No:&nbsp;<font color=red>*</font></font></td>
						   <td width="17%"><html:text name="QuotationForm" property="quotationNo" styleClass="txfield" size="23" maxlength="50" /></td>
						   <td width="13%"><font class="NArialL">Customer Name :</font></td>
						   <td width="20%" class="bodytext"><b><bean:write name="QuotationForm" property="customerName" /></b></td>
						   <td width="25%">&nbsp;</td>
						   <td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL">Customer PO No:&nbsp;<font color=red>*</font></font></td>
							<td width="17%"><html:text name="QuotationForm" property="customerPO" styleClass="txfield" size="23" maxlength="50" onkeyup=""/></td>
							<td width="13%"><font class="NArialL"><bean:message key="label.sales.quotation.contactPerson"/> :</font></td>
							<td width="20%">
								<html:select  name="QuotationForm" property="contactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('CustomerContactPerson',0);">
									<html:option value="">--- Select ---</html:option>
									<html:options name="contactPersons" />
								</html:select>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
                        <%--<tr><td colspan=4><font class="NArialL">Please <chiptrack:attachFile fileGroup="SalesOrder-PO" fileSubGroup="AUTO" formTitle="Attach Sales PO" linkText="click here" allowAttach="true" allowDelete="true"/> to View and Attach PO</font></td></tr>--%>
                        <tr>
							<td width="11%"><font class="NArialL"><bean:message key="label.sales.salesOrder.PoRevisionNumber"/> :</font></td>
							<td width="17%"><html:text name="QuotationForm" property="poRev" size="23" styleClass="txfield" /></td>
							<td width="13%"><font class="NArialL"><bean:message key="label.sales.salesOrder.PoDate"/> :</td>
							<td width="20%"><html:text name="QuotationForm" property="poDate" size="23" styleClass="txfield" />
								<a href="javascript:openCalendar(document.QuotationForm.poDate)"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL">Phone :</font></td>
							<td width="17%"><html:text name="QuotationForm" property="phoneNumber" size="23" styleClass="txfield" onkeypress='validatePhoneNumber(this)'/></td>
							<td width="13%"><font class="NArialL">Cell Phone No :</font></td>
							<td width="20%"><html:text name="QuotationForm" property="cellNumber" size="23" styleClass="txfield" disabled="false" onkeypress='validatePhoneNumber(this)'/></td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL">Fax :</font></td>
							<td width="17%"><html:text name="QuotationForm" property="faxNumber" size="23" styleClass="txfield" onkeypress='validatePhoneNumber(this)'/></td>
							<td width="13%"><font class="NArialL">Email :</font></td>
							<td width="20%"><html:text name="QuotationForm" property="email" size="23" styleClass="txfield" disabled="false" /></td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL"><bean:message key="label.sales.quotation.salesPerson"/> :</font></td>
						    <td width="17%">
								<html:select name="QuotationForm" property="salesPerson" styleClass="txfield" >
									<html:option value="" >----- Select -----</html:option>
									<html:options collection="salesPersons" property="value" labelProperty="label"/>
								</html:select>
						        <input type="hidden" name="salesPersonName" value="<%=quotationForm.getSalesPerson()%>"/>
							</td>
							<td width="13%"><font class="NArialL"><bean:message key="label.sales.salesRep.Name"/> :</font></td>
							<td width="20%">
								<html:select name="QuotationForm" property="salesRep" styleClass="txfield" >
									<html:option value="" >----- Select -----</html:option>
									<html:options collection="salesReps" property="value" labelProperty="label"/>
								</html:select>
								<html:hidden name="QuotationForm" property="salesRep" />
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
					    <tr>
							<td colspan="3">
								<font class="NArialL">Please <a styleClass="leftsection" href="javascript:selectCustomerSalesPersonRelation()" onmouseover="window.status='Click to select Customer/Sales Person Relationship';return true" onmouseout="window.status='';return true">
								Click here</a>&nbsp;to Add Customer/Sales Person Relationships
								</font>
							</td>
							<td width="8%">&nbsp;</td>
							<td width="20%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL"><bean:message key="label.sales.salesOrder.ShippingMethod" /> :</font></td>
							<td width="17%">
	   							<select name="shippingMethod" class="txfield" onchange="javascript:addShippingMethod(this);">
									<option value="-1" >----- Select -----</option>
									<%
										java.util.ArrayList shippingMethods = null;

										boolean flagValue = false;
										try
										{
											if(request != null)
											{
												selectedMethod = (String)request.getAttribute("Method");
												selectedAccount = (String)request.getAttribute("Account");
												shippingMethods = quotationFromMap.getShippingMethods();
												org.apache.struts.util.LabelValueBean shippingMethod;
												for(int j=0; j<shippingMethods.size(); j++)
												{
													shippingMethod = (org.apache.struts.util.LabelValueBean)shippingMethods.get(j);
													String label = shippingMethod.getLabel();
													String value = shippingMethod.getValue();
													if( selectedMethod != null)
													{
														if( (selectedMethod.trim()).equalsIgnoreCase(label.trim()) )
														{
									%>
															<option value="<%=selectedMethod%>" selected><%=selectedMethod%></option>
									<%
														}
														else if ( "'".equalsIgnoreCase( value ) )
														{
									%>
															<option value="-1"><%=label%></option>
									<%
														}
														else
														{
									%>
															<option value="<%=label%>" ><%=label%></option>
									<%
														}
													}
													else
													{
									%>
														<option value="<%=label%>" ><%=label%></option>
									<%				}

											}
										}
									}
									catch(NullPointerException e) { e.printStackTrace();}
									%>
									<option value="-2" >----- Edit -----</option>
								</select>
							</td>
						    <td width="13%">&nbsp;</td>
							<td width="20%">
								<input type="hidden" name="shippingAccount" value="<%=quotationForm.getShippingAccount()%>">
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL" id="newshippingMethod"><bean:message key="label.sales.salesOrder.NewShippingMethod"/>:</font></td>
							<td width="17%"><html:text name="QuotationForm" property="newshippingMethod" size="23" maxlength="50" styleClass="txfield"  /></td>
							<td width="13%"><font class="NArialL" id="newshippingAccount"><bean:message key="label.sales.salesOrder.NewShippingAccount"/>:</font></td>
							<td width='20%'><html:text name="QuotationForm" property="newshippingAccount" size="23" maxlength="50"  styleClass="txfield" /></td>
							<td width="25%">&nbsp;</td>
							<td width='13%'>&nbsp;</td>
						</tr>
						<tr>
                            <td width="11%"><font class="NArialL">Pay Terms :</font></td>
                            <td width="17%"  >
                                <html:select name="QuotationForm" property="shippingTerms" styleClass="txfield" onchange="javascript:AddShippingTerms()">
                                    <option value="" >----- Select -----</option>
                                    <html:options name="allShippingTerms" />
                                    <html:option value="-2" >-- Add New Pay Terms --</html:option>
                                </html:select>
                            </td>
                            <td width="13%"><font class="NArialL"><bean:message key="label.sales.salesOrder.DeliveryTerms" /> :</font></td>
                            <td width="20%">
                                <html:select name="QuotationForm" property="deliveryTerms" styleClass="txfield" onchange="javascript:AddDeliveryTerms()">
                                    <option value="" >----- Select -----</option>
                                    <html:options name="allDeliveryTerms"/>
                                    <html:option value="-2">-- Add New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> --</html:option>
                                </html:select>
                           </td>
                           <td width="25%">&nbsp;</td>
                           <td width="13%">&nbsp;</td>
                        </tr>
						<tr>
							<td width="11%"><font class="NArialL" id="newShippingTerms">New Pay Terms:</font></td>
							<td width="17%"><html:text name="QuotationForm" property="newShippingTerms" size="23" maxlength="50" styleClass="txfield" /></td>
							<td width="13%"><font class="NArialL" id="newDeliveryTerms">New <bean:message key="label.sales.salesOrder.DeliveryTerms" />:</font></td>
							<td width="20%"><html:text name="QuotationForm" property="newDeliveryTerms" size="23" maxlength="50" styleClass="txfield" /></td>
							<td width='25%'>&nbsp;</td>
							<td width='13%'>&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL"><bean:message key="label.sales.quotation.regionalRep"/> :</font></td>
							<td width="17%"> <html:text name="QuotationForm" property="regionalRep" size="23" styleClass="txfield" /></td>
							<td width="13%"><font class="NArialL">Booking Date :</font></td>
							<td width='20%'><html:text name="QuotationForm" property="quotationDate" size="23" styleClass="txfield" disabled="true"/>
							<td width="25%">&nbsp;</td>
							<td width='13%'>&nbsp;</td>
						</tr>

                        <tr>
                               <td width="13%"><font class="NArialL"><bean:message key="label.sales.endUser"/> :</font></td>
                               <td width="18%">
                                <html:select name="QuotationForm" property="endCustomerId" styleClass="txfield" onchange="showHideNewEndUserField()">
                                    <html:option value="" >----- Select -----</html:option>
                                    <html:options collection="endCustomerList" property="value" labelProperty="label"/>
                                    <html:option value="-2" >-----Add New-----</html:option>
                                </html:select>
                                <html:hidden name="QuotationForm" property="endCustomer" />
                                <input type="hidden" name="endUser" value="" />
                               </td>
                               <td width="15%"><font class="NArialL"><bean:message key="label.sales.shipToCustomer"/></font></td>
                               <td width="20%">
                                  <html:select name="QuotationForm" property="odmId" styleClass="txfield" onchange="javascript:getCustomerShippingAddress();"> <%--onchange="javascript:selectODM(this);"--%>
                                    <html:option value="-1" >----- Select -----</html:option>
                                    <html:options collection="odmList" property="value" labelProperty="label"/>
                                    <html:option value="-2" >-----Add New-----</html:option>
                                  </html:select>
                                <html:hidden name="QuotationForm" property="odm" />
                                </td>
                               <td width="22%">&nbsp;</td>
                               <td width="11%">&nbsp;</td>

                             </tr>
                             <tr>
                               <td class="NArialL"><span id="endUserLabelSpan" style="display:none">Add New <bean:message key="label.sales.endUser"/> :</span></td>
                               <td ><span id="endUserTxfieldSpan" style="display:none"><html:text name="QuotationForm" property="newEndUserName" styleClass="txfield"/></span></td>
                               <td class="NArialL"><span id="endCustomerLabelSpan" style="display:none">Add New <bean:message key="label.sales.shipToCustomer"/></span></td>
                               <td ><span id="endCustomerTxfieldSpan" style="display:none"><html:text name="QuotationForm" property="newEndCustomerName" styleClass="txfield"/></span></td>

                               <td width="22%">&nbsp;</td>
                               <td width="11%">&nbsp;</td>
                            </tr>

                    <%--<tr>
							<td width="11%"><font class="NArialL"><bean:message key="label.sales.endUser"/></font></td>
							<td width="17%">
								<input type="hidden" name="endUser" value=""> <!--JUST DUMMY-->
                                <html:select name="QuotationForm" property="endCustomerId" styleClass="txfield">
                                    <html:option value="" >----- Select -----</html:option>
                                    <html:options collection="endCustomerList" property="value" labelProperty="label"/>
                                </html:select>
                                <html:hidden name="QuotationForm" property="endCustomer" />
                            </td>
							<td width="13%"><font class="NArialL"><bean:message key="label.sales.shipToCustomer"/></font></td>
							<td width="20%">
								<html:select name="QuotationForm" property="odmId" styleClass="txfield" onchange="javascript:getCustomerShippingAddress();"> --%><%--onchange="javascript:selectODM(this);"--%><%--
									<html:option value="-1" >----- Select -----</html:option>
									<html:options collection="odmList" property="value" labelProperty="label"/>
								</html:select>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>--%>

						<tr>
							<td width="11%">&nbsp;</td>
							<td width="17%">&nbsp;</td>
							<td width="13%"><font class="NArialL"><bean:message key="label.sales.shipToCustomer"/> Shipping Address :</font></td>
							<td width="20%">
								<html:checkbox name="QuotationForm" property="isEndCustomerShipAddress" value="true" styleClass="txfield" onclick="javascript:getEndCustomerShippingAddress(this);" />
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
						    <td width="11%">&nbsp;</td>
							<td width="17%">&nbsp; </td>
							<td width="13%"><font class="NArialL">Shipping Addresses :</font></td>
							<td width="20%">
								<html:select name="QuotationForm" property="shippingAddressId" styleClass="txfield" onchange="javascript:assignShippingAddress(this);">
									<html:options collection="shippingAddresses" property="value" labelProperty="label"/>
								</html:select>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>

						<tr>
							<td width="11%"><font class="NArialL">Contact Person :</font></td>
							<td width="17%">
								<html:select  name="QuotationForm" property="billingContactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('BillingContactPerson',0,0);" >
									<html:option value="">--- Select ---</html:option>
									<html:options name="billingAddressContactPersons" />
								</html:select>
							</td>
							<td width="13%"><font class="NArialL">Contact Person :</font></td>
							<td width="20%">
								<html:select  name="QuotationForm" property="shippingContactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('ShippingContactPerson',0,0);">
									<html:option value="">--- Select ---</html:option>
									<html:options name="shippingAddressContactPersons" />
								</html:select>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="11%"><font class="NArialL">Billing Address :</font></td>
							<td width="17%"><html:textarea rows="13" name="QuotationForm" property="billingAddress" cols="23" styleClass="txfield" disabled="true"/></td>
							<td width="13%"><font class="NArialL">Shipping Address :</font></td>
							<td width="20%">
								<html:link styleClass="NArialL" href="javascript:AddNewShippingAddress(document.QuotationForm.shippingAddress);" onmouseover="window.status='Click to Add new Shipping Address';return true" onmouseout="window.status='';return true">Add new shipping Address</html:link>
								<br>
								<html:textarea name="QuotationForm" rows="13" cols="23" property="shippingAddress" styleClass="txfield" disabled="true"/>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr><td colsapn=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
						<tr>
							<td width="13%"><font class="NArialL">All Freight Instructions :</font></td>
							<td width="20%">
								<html:select name="QuotationForm" property="freightInstructionsId" styleClass="txfield" onchange="javascript:assignFreightInstructions(this);">
								<html:options collection="freightInstructions" property="value" labelProperty="label"/>
								</html:select>
							</td>
							<td width="13%"><font class="NArialL">All Shipping Instructions :</font></td>
							<td width="20%">
								<html:select name="QuotationForm" property="shippingInstructionsId" styleClass="txfield" onchange="javascript:assignShippingInstructions(this);">
								<html:options collection="shippingInstructions" property="value" labelProperty="label"/>
								</html:select>
							</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<tr>
							<td width="13%"><font class="NArialL" id="freightInstructionLabel">Freight Instructions :</font></td>
							<td width="20%"><html:textarea name="QuotationForm" property="freightInstructions" rows="4" cols="35" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.QuotationForm.freightInstructions,300)" onkeyup="javascript:setTextAreaMaxLength(document.QuotationForm.freightInstructions,300)"/></td>
							<td width="13%"><font class="NArialL" id="shippingInstructions"><bean:message key="label.sales.shippingInstructions" /></font></td>
							<!-- Modified by SureshReddy on [09 JUNE 2004] onkeydown="" & onkeyup="" are added to "html:textarea" tag for maxlength validation-->
							<td width="20%"><html:textarea name="QuotationForm" property="shippingInstructions" rows="4" cols="35" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.QuotationForm.shippingInstructions,300)" onkeyup="javascript:setTextAreaMaxLength(document.QuotationForm.shippingInstructions,300)"/></td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
						<script>setReadOnlyForFreightInsructions ( document.QuotationForm.freightInstructionsId );</script>
						<tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
						<tr>
							<td width="11%"><font class="NArialL">Quotation Expires On :&nbsp;<font color=red>*</font></font></td>
							<td width="17%"><html:text name="QuotationForm"  property="expiryDate" styleClass="txfield" disabled="true" /></td>
							<td width="11%">&nbsp;</td>
							<td width="17%">&nbsp;</td>
							<td width="25%">&nbsp;</td>
							<td width="13%">&nbsp;</td>
						</tr>
                        <tr>
							<td width="11%" class="NArialL">Comments :</td>
							<td width="89%" colspan="5">
                                <html:textarea name="QuotationForm" property="comments" rows="4" cols="100" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.QuotationForm.comments,300)" onkeyup="javascript:setTextAreaMaxLength(document.QuotationForm.comments,300)"/>
                            </td>
						</tr>
                        <%
                            String commentsGroupId = "Quotation-" + quotationForm.getSalesOrderQuoteNo();
                        %>
                        <tr><td colspan=4><chiptrack:internalComments commentsGroupId="<%=commentsGroupId%>"/></td></tr>
                        <tr>
                            <td colspan="6" width="12%"><jsp:include page="previously_modified_quotation_line_items.jsp" flush="true" /></td>
                        </tr>
                        <tr>
                            <td colspan="6" width="12%"><jsp:include page="previously_transferred_quotation_line_items.jsp" flush="true" /></td>
                        </tr>
                        <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
						<tr><td colspan='6' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
						<tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
						<tr>
							<td colspan=6>
								<br>
								<font class="NArialS" color='blue'><b><li>&nbsp;Disabled LineItem indicates either not Approved or totally Transfered.</b></font><br>
								<br>
								<table border="0" width="95%" bordercolor="#FFFFFF">
                                    <tr>
                                        <TD colspan=3 class="NArialL"><a href="javascript:splitLineItems()">Split Line Items</a></TD>
                                    </tr>
                                    <tr>
                                        <TD colspan=3>&nbsp;</TD>
                                    </tr>
                                    <tr>
										<td width="8%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Close</font></font></td>
										<td width="8%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Transfer</font></font></td>
										<td width="8%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Line Item</font></font></td>
										<td width="8%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">PO Line Item</font></font></td>
										<td width="20%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF"><bean:message key="label.mfgPartNumber" />&nbsp;*</font></font></td>
										<td width="20%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF"><bean:message key="label.customerPartNumber"/></font></font></td>
										<td width="20%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Description</font></font></td>
										<td width='1%' align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Taxable</font></font></td>
										<td width="14%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Req'd Dock Date<br><font size="-3">(mm/dd/yyyy)</font>&nbsp;*</font></font></td>
                                        
                                        <td width="5%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Quantity&nbsp;*</font></font></td>
										<td width="10%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Price($) </font></font></td>
										<td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Amount</font></font></td>
									</tr>

									<jsp:include page="include_quotation_line_items.jsp" flush="true" />

									<tr><td colspan='12' align="left"><FONT id="font1"></FONT></TD></TR>
									<tr><td colspan="12">&nbsp;</td></tr>
									<tr>
										<td colspan="11" align="right" bgcolor="#FFFFFF" class="NArialL">Total</td>
										<td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;<html:text name="QuotationForm" property="subTotalAsString" disabled="true" styleClass="valuetxfield" size="25"/></td>
									</tr>
									<tr>
										<td colspan="5" class="NArialL" align=right>Sales Tax State</td>
										<td class="NArialL">
											<html:select name="QuotationForm" property="salesTaxType" styleClass="txfield" onchange="javascript:addNewSalesTaxType(this);">
												<html:option value="0" >Non Taxable</html:option>
												<html:options collection="salesTaxes" property="value" labelProperty="label" />
												<html:option value="-1">Others</html:option>
											</html:select>
										</td>
										<td colspan="5" align=right class="NArialL">Sales Tax</td>
										<td width="15%" class="NArialL" >&nbsp;&nbsp;<html:text name="QuotationForm" property="salesTaxAsString" styleClass="valuetxfield"  size="25" disabled="true"/></td>
									</tr>
									<tr>
										<td colspan=5 align=right class="NArialL"><font class="NArialL"><FONT id="font-1"></FONT></font></td>
										<td class="NarialL" ><font class="NArialL"><FONT id="font-2"></FONT></font></td>
										<td colspan="1" class="NArialL">&nbsp;</td>
										<td colspan="4" align=right class="NArialL">Freight</td>
										<td width="15%" class="NArialL">$<html:text name="QuotationForm" property="frieghtAsDouble" styleClass="valuetxfield"  size="25" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,3)" onkeyup="javascript:restrictAmt(this,7,3)"/></td>
									</tr>
									<tr>
										<td colspan=5 align=right class="NArialL"><font class="NArialL"><FONT id="font-3"></FONT></font></td>
										<td class="NarialL" ><font class="NArialL"><FONT id="font-4"></FONT></font></td>
										<td colspan="1" class="NArialL">&nbsp;</td>
										<td colspan="4" align=right class="NArialL"><html:text name="QuotationForm" property="miscName" styleClass="valuetxfield"/></td>
										<td width="15%" class="NArialL">$<html:text name="QuotationForm" property="miscAsDouble" styleClass="valuetxfield" size="25" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,3)" onkeyup="javascript:restrictAmt(this,7,3)"/></td>
									</tr>
									<tr>
										<td colspan="11" align=right class="NArialL">Order Total</td>
										<td width="15%" class="NArialL">&nbsp;&nbsp;<html:text name="QuotationForm" property="orderTotalAsString" disabled="true" styleClass="valuetxfield" size="25"/></td>
									</tr>
									<tr><td colspan="12">&nbsp;</td></tr>
									<tr>
										<td colspan="10">&nbsp</td>
										<td align="center">&nbsp;</td>
										<td width="15%" align="center"><chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('UPDATE');" ><img src="<%=chipTracContext%>/jsp/includes/images/calculate.gif" onmouseover="window.status='Click to Calculate Order total';return true" onmouseout="window.status='';return true" title="Click here to Calculate Order total" border='0'></chiptrack:restrictedLink></td>
									</tr>
								</table>
							</td>
						</tr>
                        <tr>
                            <td colspan=6 align=center>
                                <chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SUBMIT');" >
                                    <img src="<%=chipTracContext%>/jsp/includes/images/submit.gif" onmouseover="window.status='Click to Transfer Quote';return true" onmouseout="window.status='';return true" title="Click here to transfer Quote" border='0'>
                                </chiptrack:restrictedLink>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="javascript:resetForm()"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif"onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset" border='0'></a>
                             </td>
                        </tr>
                    </table>
                    <input type="hidden" name="salesOrderQuoteNo" value="<%=quotationForm.getSalesOrderQuoteNo() %>" >
                    <input type="hidden" name="customerName" value="<%=quotationForm.getCustomerName()%>" >
                    <input type="hidden" name="customerId" value="<%=quotationForm.getCustomerId()%>" >
                    <input type="hidden" name="billingAddressId" value="<%=quotationForm.getBillingAddressId()%>">
                    <input type="hidden" name="shippingMethodName"value="<%=quotationForm.getShippingMethodName()%>" >
                    <input type="hidden" name="quotationDate" value="<%=quotationForm.getQuotationDate()%>">

                    <input type="hidden" name="isSample" value="<%=request.getParameter("isSample")%>">
                    <input type="hidden" name="action" value="">

                    <input type="hidden" name="selectedMethod" value="<%=selectedMethod%>">
                    <input type="hidden" name="selectedAccount" value="<%=selectedAccount%>">
                    <input type="hidden" name="shipAccount1" value="<%=request.getAttribute("Method")%>"/>
                    </html:form>
                </html:html>
<!-- till here -->
        <BR><BR><BR></TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
<%
    if ( "false".equalsIgnoreCase((String)request.getAttribute("otherstateadded")) ) { %>
    <script language="javascript">
        addNewSalesTaxType(document.QuotationForm.salesTaxType);
        document.QuotationForm.newSalesState.value = "<%=request.getAttribute("newsalesstate") %>"
        document.QuotationForm.newSalesTax.value = "<%=request.getAttribute("newsalesvalue") %>"
    </script>
<% } %>
<script language="javascript">var no = <%=i%>;</script>
<script language="javascript">
function checkValidity(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if(field == 'Contact Person') {
        field_vlaue = document.QuotationForm.contactPerson.value;
        field_focus = "contactPerson";
    }

    if(field == 'Sales Person') {
        field_vlaue = document.QuotationForm.salesPerson.value;
        field_focus = "salesPerson";
    }

    if(field == 'Regional Rep'){
        field_vlaue = document.QuotationForm.regionalRep.value;
        field_focus = "regionalRep";
    }

    if(field == 'End User'){
        field_vlaue = document.QuotationForm.endUser.value;
        field_focus = "endUser";
    }

    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    for(i=0;i<field_vlaue.length;i++)
    {
        var str = field_vlaue.charAt(i)
        if ( (str == "$") || (str == "#") || (str == "(") || (str == ")") )
        {
            var errMsg = "* " + field +" can not contain #,$,(, and )  Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.QuotationForm."+field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkCustomerPONumber(field)
{
    var field_vlaue = document.QuotationForm.customerPO.value;
    var field_focus = "customerPO";
    var pa=document.getElementById("errors");
    pa.innerHTML = "&nbsp;";

    for(i=0;i<field_vlaue.length;i++)
	{
        var str = field_vlaue.charAt(i)
        if(i==0 && str==" ")
        {
            var errMsg = "* " + field +" can not start with a space";
            pa.innerHTML = errMsg;
            var obj = eval("document.QuotationForm."+field_focus);
            obj.focus();
            return false;
        }
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "* " + field +" can not contain # $ ( ) . , and &";
            pa.innerHTML = errMsg;
            var obj = eval("document.QuotationForm."+field_focus);
            obj.focus();
            return false;
        }
	}
 }

function checkShipping(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if(field == 'Shipping Account') {
        field_vlaue = document.QuotationForm.shippingAccount.value;
        field_focus = "shippingAccount";
    }

    if(field == 'New Shipping Method') {
        field_vlaue = document.QuotationForm.newshippingMethod.value;
        field_focus = "newshippingMethod";
    }

    if(field == 'New Shipping Account'){
        field_vlaue = document.QuotationForm.newshippingAccount.value;
        field_focus = "newshippingAccount";
    }

    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    for(i=0;i<field_vlaue.length;i++)
	{
        var str = field_vlaue.charAt(i)
        if ( (str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ",") )
        {
            var errMsg = "* " + field +" can not contain # $ ( ) . , and & Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.QuotationForm."+field_focus);
            obj.focus();
            return false;
        }
	}
 }

 function checkForDot(field)
 {
    var field_vlaue = document.QuotationForm.shippingTerms.value;
    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    for(i=0;i<field_vlaue.length;i++)
	{
        var str = field_vlaue.charAt(i)
        if ( (str == ".") )
        {
            var errMsg = "* " + field +" can not contain . Character";
            pa.innerHTML = errMsg;
            document.QuotationForm.shippingTerms.focus();
            return false;
        }
	}
 }

function checkForBraces(field)
{
    var field_vlaue = document.QuotationForm.deliveryTerms.value;
    var pa=document.getElementById("errors");
    pa.innerHTML = "";

    for(i=0;i<field_vlaue.length;i++)
    {
        var str = field_vlaue.charAt(i)
        if ( (str == "(") || (str == ")") )
        {
            var errMsg = "* " + field +" can not contain '(' and ')' Characters";
            pa.innerHTML = errMsg;
            document.QuotationForm.deliveryTerms.focus();
            return false;
        }
    }
}
</script>
</BODY>
</HTML>

